<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="util" uri="/WEB-INF/kdd-util.tld" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<sec:authorize access="isAuthenticated()">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        </head>
        <body>
            <jsp:include page="menu.jsp" />
            <script type="text/javascript">
                $(function() { 
                    var t = $('table#listtable')
                    $("#filter").keyup(function() {
                        $.uiTableFilter( t, this.value );
                    })
                });
                $(function() { 
                    var t = $('table#datatable')
                    $("#datafilter").keyup(function() {
                        $.uiTableFilter( t, this.value );
                    })
                });
            </script>
            <div class="notfullnomargin">
                <h3>${project.name}<br /><small> <spring:message code="msg.createdby" /> ${project.creator.username} <spring:message code="msg.on" />: <fmt:formatDate value="${project.creationDate}" pattern="MM/dd/yyyy HH:mm"/><br />
                        <spring:message code="msg.parentis" /> <a href="<c:url value='/project/${project.parent.id}' />">${project.parent.name}</a></small></h3><br />
                <div class="well columnleft">
                    <b><spring:message code="msg.researchers" />:</b><br /><br />
                    <c:choose>
                        <c:when test="${empty project.researchers}">
                            <spring:message code="msg.noresearchers" />
                        </c:when>
                        <c:otherwise>
                            <input type="text" id="researcherfilter" placeholder="Filter" />
                            <ul id="researcherlist">
                                <c:forEach items="${project.researchers}" var="sp">
                                    <li><span>${sp.username}</span></li>
                                </c:forEach>
                            </ul>
                        </c:otherwise>
                    </c:choose>
                </div>
                <div class="columnholder row">
                    <div class="well columnright">
                        <b><spring:message code="msg.sharedtousers" />:</b><br /><br />
                        <c:choose>
                            <c:when test="${empty project.sharedUserList}">
                                <spring:message code="msg.nosharedusers" />
                            </c:when>
                            <c:otherwise>
                                <input type="text" id="sharedfilter" placeholder="Filter" />
                                <ul id="shareduserlist">
                                    <c:forEach items="${project.sharedUserList}" var="u">
                                        <li><span>${u.username}</span>
                                            <c:if test="${not empty isLeader}">[<a href="<c:url value='/subproject/deleteSharedUser/${project.id}/${u.username}' />">x</a>]</c:if>
                                        </li>
                                    </c:forEach>
                                </ul>
                                <br />
                            </c:otherwise>
                        </c:choose>
                        <c:if test="${not empty isLeader}">
                            <div class="ui-widget">
                                <c:url var="userListAction" value="/subproject/addSharedUser/${project.id}" />
                                <form class="nomargin" method="POST" action="${userListAction}" modelAttribute="shareuser">
                                    <select name="sharedUserAdd" class="usermulti">
                                        <c:forEach items="${users}" var="u">
                                            <option value="${u}">${u}</option>
                                        </c:forEach>
                                    </select>
                                    <button type="submit" class="btn btn-mini btn-primary"><spring:message code="msg.add" /></button>
                                </form>
                            </div>
                        </c:if>
                    </div>
                </div>
                <c:if test="${not empty project.description}">
                    <div class="well">
                        <b><spring:message code="msg.description" />:</b><br /><br />
                        ${util:nl2br(project.description)}
                    </div>
                </c:if>
                <div class="well">
                    <b><spring:message code="msg.results" />:</b><br /><br />
                    <c:choose>
                        <c:when test="${empty results}">
                            <spring:message code="msg.noresults" />
                        </c:when>
                        <c:otherwise>
                            <input type="text" id="filter" placeholder="Filter" />
                            <table id="listtable" class="table table-striped table-bordered table-condensed">
                                <thead>
                                    <tr>
                                        <th class="creationdate"><spring:message code="msg.creationdate" /></th>
                                        <th><spring:message code="msg.method" /></th>
                                        <th><spring:message code="msg.creator" /></th>
                                        <th class="details"><spring:message code="msg.details" /></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <c:forEach items="${results}" var="r">
                                        <tr>
                                            <td><fmt:formatDate value="${r.creationDate}" pattern="MM/dd/yyyy HH:mm"/></td>
                                            <td>${r.method.showName}</td>
                                            <td>${r.creator.username}</td>
                                            <td><a href="<c:url value='/result/${r.id}'/>"><spring:message code="msg.details" /></a></td>
                                        </tr>
                                    </c:forEach>
                                </tbody>
                            </table>
                        </c:otherwise>
                    </c:choose>
                </div>
                <c:if test="${not empty events}">
                    <div class="well notfull">
                        <h4><spring:message code="msg.events" /></h4><br />
                        <div>
                            <input type="text" id="datafilter" placeholder="Filter" />
                            <table id="datatable" class="table table-bordered table-condensed notfull">
                                <thead>
                                    <tr>
                                        <th><spring:message code="msg.events" /></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <c:forEach items="${events}" var="e">
                                        <tr>
                                            <td class="${util:getTypeColor(e.type)} borderbottom">
                                                <strong><spring:message code="msg.subproject" />:</strong> <a href="<c:url value='/subproject/${e.subProject.id}'/>">${e.subProject.name}</a>
                                                - <strong><spring:message code="msg.created" />:</strong> <fmt:formatDate value="${e.creationDate}" pattern="MM/dd/yyyy HH:mm"/><br />
                                                ${e.text}
                                            </td>
                                        </tr>
                                    </c:forEach>
                                </tbody>
                            </table>
                            <strong><a href="<c:url value='/events/subproject/${project.id}'/>"><spring:message code="msg.showallevents" /></a></strong>
                        </div>
                    </div>
                </c:if>
                <c:url var="commentAction" value="/comment/subproject/add/${project.id}" />
                <%@include file="includes/commentform.jsp"%>
                <c:if test="${not empty comments}">
                    <div>
                        <b><spring:message code="msg.comments" />:</b><br /><br />
                        <c:forEach items="${comments}" var="pc">
                            <div class="well">
                                <h5>${pc.creator.username}, <small><fmt:formatDate value="${pc.creationDate}" pattern="MM/dd/yyyy HH:mm"/></small></h5><br />
                                ${util:nl2br(pc.text)}
                            </div>
                        </c:forEach>
                    </div>
                </c:if>
            </div>
            <script type="text/javascript">
                $(".usermulti").chosen();
            </script>
            <script type="text/javascript">
                $("#sharedfilter").keyup( function() {
                    filterList($("#shareduserlist"), $(this).val());
                });
                $("#researcherfilter").keyup( function() {
                    filterList($("#researcherlist"), $(this).val());
                });
            </script>
            <jsp:include page="foot.jsp" />
        </sec:authorize>